//
// Copyright (c) 2016-2019 Kris Jusiak (kris at jusiak dot net)
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#include <type_traits>

template <class...> struct type {};
template <class...> struct type_list { using type = type_list; };

template <class... Ts> struct inherit : Ts... { using type = inherit; };

struct none_type {};

template <class...> struct unique;

template <class... Rs, class T, class... Ts>
struct unique<type<Rs...>, T, Ts...>
    : std::conditional_t<std::is_base_of<type<T>, inherit<type<Rs>...>>::value,
                         unique<type<Rs...>, Ts...>,
                         unique<type<Rs..., T>, Ts...>> {};

template <class... Rs> struct unique<type<Rs...>> : type_list<Rs...> {};
template <class... Ts> using unique_t = typename unique<type<>, Ts...>::type;

int main() {
  using u = unique_t<
      std::integral_constant<int, 1>, std::integral_constant<int, 2>,
      std::integral_constant<int, 3>, std::integral_constant<int, 4>,
      std::integral_constant<int, 5>, std::integral_constant<int, 6>,
      std::integral_constant<int, 7>, std::integral_constant<int, 8>,
      std::integral_constant<int, 9>, std::integral_constant<int, 10>,
      std::integral_constant<int, 11>, std::integral_constant<int, 12>,
      std::integral_constant<int, 13>, std::integral_constant<int, 14>,
      std::integral_constant<int, 15>, std::integral_constant<int, 16>,
      std::integral_constant<int, 17>, std::integral_constant<int, 18>,
      std::integral_constant<int, 19>, std::integral_constant<int, 20>,
      std::integral_constant<int, 21>, std::integral_constant<int, 22>,
      std::integral_constant<int, 23>, std::integral_constant<int, 24>,
      std::integral_constant<int, 25>, std::integral_constant<int, 26>,
      std::integral_constant<int, 27>, std::integral_constant<int, 28>,
      std::integral_constant<int, 29>, std::integral_constant<int, 30>,
      std::integral_constant<int, 31>, std::integral_constant<int, 32>,
      std::integral_constant<int, 33>, std::integral_constant<int, 34>,
      std::integral_constant<int, 35>, std::integral_constant<int, 36>,
      std::integral_constant<int, 37>, std::integral_constant<int, 38>,
      std::integral_constant<int, 39>, std::integral_constant<int, 40>,
      std::integral_constant<int, 41>, std::integral_constant<int, 42>,
      std::integral_constant<int, 43>, std::integral_constant<int, 44>,
      std::integral_constant<int, 45>, std::integral_constant<int, 46>,
      std::integral_constant<int, 47>, std::integral_constant<int, 48>,
      std::integral_constant<int, 49>, std::integral_constant<int, 50>,
      std::integral_constant<int, 51>, std::integral_constant<int, 52>,
      std::integral_constant<int, 53>, std::integral_constant<int, 54>,
      std::integral_constant<int, 55>, std::integral_constant<int, 56>,
      std::integral_constant<int, 57>, std::integral_constant<int, 58>,
      std::integral_constant<int, 59>, std::integral_constant<int, 60>,
      std::integral_constant<int, 61>, std::integral_constant<int, 62>,
      std::integral_constant<int, 63>, std::integral_constant<int, 64>,
      std::integral_constant<int, 1>, std::integral_constant<int, 65>,
      std::integral_constant<int, 66>, std::integral_constant<int, 67>,
      std::integral_constant<int, 68>, std::integral_constant<int, 69>,
      std::integral_constant<int, 70>, std::integral_constant<int, 71>,
      std::integral_constant<int, 72>, std::integral_constant<int, 73>,
      std::integral_constant<int, 74>, std::integral_constant<int, 75>,
      std::integral_constant<int, 76>, std::integral_constant<int, 77>,
      std::integral_constant<int, 78>, std::integral_constant<int, 79>,
      std::integral_constant<int, 80>, std::integral_constant<int, 81>,
      std::integral_constant<int, 82>, std::integral_constant<int, 83>,
      std::integral_constant<int, 84>, std::integral_constant<int, 85>,
      std::integral_constant<int, 86>, std::integral_constant<int, 87>,
      std::integral_constant<int, 88>, std::integral_constant<int, 89>,
      std::integral_constant<int, 90>, std::integral_constant<int, 91>,
      std::integral_constant<int, 92>, std::integral_constant<int, 93>,
      std::integral_constant<int, 94>, std::integral_constant<int, 95>,
      std::integral_constant<int, 96>, std::integral_constant<int, 97>,
      std::integral_constant<int, 98>, std::integral_constant<int, 99>,
      std::integral_constant<int, 100>, std::integral_constant<int, 101>,
      std::integral_constant<int, 102>, std::integral_constant<int, 103>,
      std::integral_constant<int, 104>, std::integral_constant<int, 105>,
      std::integral_constant<int, 106>, std::integral_constant<int, 107>,
      std::integral_constant<int, 108>, std::integral_constant<int, 109>,
      std::integral_constant<int, 110>, std::integral_constant<int, 111>,
      std::integral_constant<int, 112>, std::integral_constant<int, 113>,
      std::integral_constant<int, 114>, std::integral_constant<int, 115>,
      std::integral_constant<int, 116>, std::integral_constant<int, 117>,
      std::integral_constant<int, 118>, std::integral_constant<int, 119>,
      std::integral_constant<int, 120>, std::integral_constant<int, 121>,
      std::integral_constant<int, 122>, std::integral_constant<int, 123>,
      std::integral_constant<int, 124>, std::integral_constant<int, 125>,
      std::integral_constant<int, 126>, std::integral_constant<int, 127>,
      std::integral_constant<int, 128>, std::integral_constant<int, 56>>;

  static_assert(
      std::is_same<
          type_list<
              std::integral_constant<int, 1>, std::integral_constant<int, 2>,
              std::integral_constant<int, 3>, std::integral_constant<int, 4>,
              std::integral_constant<int, 5>, std::integral_constant<int, 6>,
              std::integral_constant<int, 7>, std::integral_constant<int, 8>,
              std::integral_constant<int, 9>, std::integral_constant<int, 10>,
              std::integral_constant<int, 11>, std::integral_constant<int, 12>,
              std::integral_constant<int, 13>, std::integral_constant<int, 14>,
              std::integral_constant<int, 15>, std::integral_constant<int, 16>,
              std::integral_constant<int, 17>, std::integral_constant<int, 18>,
              std::integral_constant<int, 19>, std::integral_constant<int, 20>,
              std::integral_constant<int, 21>, std::integral_constant<int, 22>,
              std::integral_constant<int, 23>, std::integral_constant<int, 24>,
              std::integral_constant<int, 25>, std::integral_constant<int, 26>,
              std::integral_constant<int, 27>, std::integral_constant<int, 28>,
              std::integral_constant<int, 29>, std::integral_constant<int, 30>,
              std::integral_constant<int, 31>, std::integral_constant<int, 32>,
              std::integral_constant<int, 33>, std::integral_constant<int, 34>,
              std::integral_constant<int, 35>, std::integral_constant<int, 36>,
              std::integral_constant<int, 37>, std::integral_constant<int, 38>,
              std::integral_constant<int, 39>, std::integral_constant<int, 40>,
              std::integral_constant<int, 41>, std::integral_constant<int, 42>,
              std::integral_constant<int, 43>, std::integral_constant<int, 44>,
              std::integral_constant<int, 45>, std::integral_constant<int, 46>,
              std::integral_constant<int, 47>, std::integral_constant<int, 48>,
              std::integral_constant<int, 49>, std::integral_constant<int, 50>,
              std::integral_constant<int, 51>, std::integral_constant<int, 52>,
              std::integral_constant<int, 53>, std::integral_constant<int, 54>,
              std::integral_constant<int, 55>, std::integral_constant<int, 56>,
              std::integral_constant<int, 57>, std::integral_constant<int, 58>,
              std::integral_constant<int, 59>, std::integral_constant<int, 60>,
              std::integral_constant<int, 61>, std::integral_constant<int, 62>,
              std::integral_constant<int, 63>, std::integral_constant<int, 64>,
              std::integral_constant<int, 65>, std::integral_constant<int, 66>,
              std::integral_constant<int, 67>, std::integral_constant<int, 68>,
              std::integral_constant<int, 69>, std::integral_constant<int, 70>,
              std::integral_constant<int, 71>, std::integral_constant<int, 72>,
              std::integral_constant<int, 73>, std::integral_constant<int, 74>,
              std::integral_constant<int, 75>, std::integral_constant<int, 76>,
              std::integral_constant<int, 77>, std::integral_constant<int, 78>,
              std::integral_constant<int, 79>, std::integral_constant<int, 80>,
              std::integral_constant<int, 81>, std::integral_constant<int, 82>,
              std::integral_constant<int, 83>, std::integral_constant<int, 84>,
              std::integral_constant<int, 85>, std::integral_constant<int, 86>,
              std::integral_constant<int, 87>, std::integral_constant<int, 88>,
              std::integral_constant<int, 89>, std::integral_constant<int, 90>,
              std::integral_constant<int, 91>, std::integral_constant<int, 92>,
              std::integral_constant<int, 93>, std::integral_constant<int, 94>,
              std::integral_constant<int, 95>, std::integral_constant<int, 96>,
              std::integral_constant<int, 97>, std::integral_constant<int, 98>,
              std::integral_constant<int, 99>, std::integral_constant<int, 100>,
              std::integral_constant<int, 101>,
              std::integral_constant<int, 102>,
              std::integral_constant<int, 103>,
              std::integral_constant<int, 104>,
              std::integral_constant<int, 105>,
              std::integral_constant<int, 106>,
              std::integral_constant<int, 107>,
              std::integral_constant<int, 108>,
              std::integral_constant<int, 109>,
              std::integral_constant<int, 110>,
              std::integral_constant<int, 111>,
              std::integral_constant<int, 112>,
              std::integral_constant<int, 113>,
              std::integral_constant<int, 114>,
              std::integral_constant<int, 115>,
              std::integral_constant<int, 116>,
              std::integral_constant<int, 117>,
              std::integral_constant<int, 118>,
              std::integral_constant<int, 119>,
              std::integral_constant<int, 120>,
              std::integral_constant<int, 121>,
              std::integral_constant<int, 122>,
              std::integral_constant<int, 123>,
              std::integral_constant<int, 124>,
              std::integral_constant<int, 125>,
              std::integral_constant<int, 126>,
              std::integral_constant<int, 127>,
              std::integral_constant<int, 128>>,
          u>{},
      "");
}
